package com.sunday.common.statemachine.study.e2_Config;

import org.springframework.statemachine.config.model.*;

import java.util.ArrayList;
import java.util.Collection;

/**
 * <a href="https://docs.spring.io/spring-statemachine/docs/4.0.0/reference/index.html#configuring-model">...</a>
 * 这个其实可以连接数据进行自定义流程的创建了
 *
 * @author sunday
 * @since 2024/12/6
 */
public class CustomStateMachineModelFactory implements StateMachineModelFactory<String, String> {

    @Override
    public StateMachineModel<String, String> build() {
        ConfigurationData<String, String> configurationData = new ConfigurationData<>();
        Collection<StateData<String, String>> stateData = new ArrayList<>();
        stateData.add(new StateData<String, String>("S1", true));
        stateData.add(new StateData<String, String>("S2"));
        StatesData<String, String> statesData = new StatesData<>(stateData);
        Collection<TransitionData<String, String>> transitionData = new ArrayList<>();
        transitionData.add(new TransitionData<String, String>("S1", "S2", "E1"));
        TransitionsData<String, String> transitionsData = new TransitionsData<>(transitionData);
        StateMachineModel<String, String> stateMachineModel = new DefaultStateMachineModel<String, String>(configurationData,
                statesData, transitionsData);
        return stateMachineModel;
    }

    @Override
    public StateMachineModel<String, String> build(String machineId) {
        return build();
    }
}